#!/usr/bin/env python3.8
# -*- encoding: utf-8 -*-
'''
@File    :   extensions.py
@Time    :   2021/10/13 16:48:57
@Author  :   windstarry 
@Version :   1.0
'''
# here put the import lib
from flask_sqlalchemy import SQLAlchemy
from flask_bootstrap import Bootstrap
from flask_login import LoginManager,AnonymousUserMixin
from flask_moment import Moment
from flask_wtf import CSRFProtect
from flask_mail import Mail
from flask_avatars import Avatars
from flask_migrate import Migrate
from flask_dropzone import Dropzone
from flask_wtf import CSRFProtect


db = SQLAlchemy()
bootstrap = Bootstrap()
moment = Moment()
migrate = Migrate()
csrf = CSRFProtect()
mail = Mail()
avatars = Avatars()
dropzone = Dropzone()
csrf = CSRFProtect()
login_manager = LoginManager()


@login_manager.user_loader
def load_user(user_id):
    from albumy.models import User
    user = User.query.get(int(user_id))
    return user

#定义flask-login的登录视图
login_manager.login_view = 'auth.login'
#义flask-login的登录消息，默认为'Please log in to access this page.'
login_manager.login_message = '请先登录'


#定义访客类
class Guest(AnonymousUserMixin):

    def can(self, permission_name):
        return False

    @property
    def is_admin(self):
        return False


login_manager.anonymous_user = Guest
